﻿@using HmPMer.Entity
@model List<HmPMer.Entity.RiskScheme>

@{
    Layout = "~/Views/Shared/_Content.cshtml";
    string TargetId = ViewBag.TargetId;
    string RiskSchemeId = ViewBag.RiskSchemeId;
    int RiskType = ViewBag.RiskType;
}

<style>
    .linksAdd .layui-form-label {
        width: 125px;
    }

    .linksAdd .layui-input-block {
        margin-left: 140px;
    }

    .div1 {
        width: 40%;
        float: left;
        margin-top: 5px;
    }
</style>
<body class="childrenBody">
    <form class="layui-form linksAdd">
        @Html.Hidden("TargetId", TargetId)
        @Html.Hidden("RiskType", RiskType)
        @if (Model != null && Model.Count > 0)
        {
            <div style="width:100%">
                <div>
                    <label class="layui-form-label"><span>是否应用</span></label>
                    <input type="checkbox" id="cbkenble" name="CbkIsEnabled" lay-filter="CbkIsEnabled" lay-skin="switch" lay-text="应用|关闭" @(!string.IsNullOrEmpty(RiskSchemeId) ? "checked" : "") />
                </div>
                <br />


                @foreach (var item in Model)
                {
                    <div class="div1">
                        <div class="layui-input-block">
                            <input type="radio" name="riskScheme" value="@item.RiskSchemeId" title="@item.SchemeName" @(!string.IsNullOrEmpty(RiskSchemeId) && RiskSchemeId.Equals(item.RiskSchemeId) ? "checked" : "") />
                        </div>
                    </div>
                }

            </div>

            <div class="layui-form-item" style="text-align:center;padding-top:10px">
                <button class="layui-btn" lay-filter="addLink" type="button" style="width:100px;" id="btn_update_risk">提交</button>
            </div>
        }
        else
        {
            <div class="layui-form-item" style="text-align:center;padding-top:20px;font-size:20px">
                请先设置风控方案
            </div>
        }
    </form>
</body>

<script>

    layui.use(['hm', 'form', 'layer'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            hm = layui.hm;

        //提交数据
        $("#btn_update_risk").click(function () {

            var list = [];
            var riskSchemeId = '';
            var riskType = $("#RiskType").val();
            var targetId = $("#TargetId").val();
            var aloneRisk = 0;

            var cbkenble = $('#cbkenble');
            if (cbkenble.is(':checked')) {
                aloneRisk = 1;
            }
            $("input[name=riskScheme]").each(function () {
                if (this.checked) {
                    riskSchemeId = this.value;
                }
            });
            list.push({ 'RiskSettingType': riskType, 'RiskSchemeId': riskSchemeId, 'TargetId': targetId });

            hm.ajax("Risk/SetRiskSetting", {
                data: {
                    list: list,
                    riskSchemeId: riskSchemeId,
                    riskType: riskType,
                    aloneRisk: aloneRisk
                },
                type: "POST",
                dataType: 'json',
                success: function (result) {
                    if (result.IsSuccess) {
                        layer.msg("操作成功！", { icon: 1, time: 300 });
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.tableIns.reload();
                            parent.layer.close(index);
                        }, 1200);
                    }
                    else {
                        layer.msg(result.message);
                    }
                },
                error: function (x, t, e) {
                    layer.closeAll();
                }
            });


        });

    })
</script>
